using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VVVLEKL
    {
        public DataRow Convert2VVLEKL(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryVVLEKL(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["VVLMANDANT"] = " ".PadRight(2 ); 
         dwReturn["VVLLEKLNR"] = " ".PadRight(8 ); 
         dwReturn["VVLAENZL"] = " ".PadRight(0 ); 
         dwReturn["VVLAENB"] = " ".PadRight(8 ); 
         dwReturn["VVLAEND"] = " ".PadRight(0 ); 
         dwReturn["VVLNEUB"] = " ".PadRight(8 ); 
         dwReturn["VVLNEUD"] = " ".PadRight(0 ); 
         dwReturn["VVLKUNDNR"] = " ".PadRight(8 ); 
         dwReturn["VVLVB"] = " ".PadRight(3 ); 
         dwReturn["VVLKUNDNRL"] = " ".PadRight(8 ); 
         dwReturn["VVLADRSLL"] = " ".PadRight(8 ); 
         dwReturn["VVLVART"] = " ".PadRight(24 ); 
         dwReturn["VVLVARTOG"] = " ".PadRight(24 ); 
         dwReturn["VVLBHS"] = " ".PadRight(1 ); 
         dwReturn["VVLFRACHT"] = " ".PadRight(0 ); 
         dwReturn["VVLPREIS"] = " ".PadRight(0 ); 
         dwReturn["VVLPREH"] = " ".PadRight(3 ); 
         dwReturn["VVLPREHGRP"] = " ".PadRight(1 ); 
         dwReturn["VVLPREHFKT"] = " ".PadRight(12 ); 
         dwReturn["VVLPWAEHRSL"] = " ".PadRight(3 ); 
         dwReturn["VVLVONDAT"] = " ".PadRight(0 ); 
         dwReturn["VVLBISDAT"] = " ".PadRight(0 ); 
         dwReturn["VVLRECHNR"] = " ".PadRight(0 ); 
         dwReturn["VVLWIDERR"] = " ".PadRight(0 ); 
         dwReturn["VVLERLKZ"] = " ".PadRight(1 ); 
         dwReturn["VVLURLAND"] = " ".PadRight(3 ); 
         dwReturn["VVLPRFBEG"] = " ".PadRight(1 ); 
         dwReturn["VVLFORM"] = " ".PadRight(8 ); 
         dwReturn["VVLZSACHB"] = " ".PadRight(8 ); 
         dwReturn["VVLZOLLTNR"] = " ".PadRight(20 ); 
         dwReturn["VVLZOLLTRW"] = " ".PadRight(20 ); 
         dwReturn["VVLDRDAT"] = " ".PadRight(0 ); 
         dwReturn["VVLFILLER"] = " ".PadRight(80 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapVVLEKL(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveVVLEKL(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryVVLEKL(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapVVLEKL(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertVVLEKL(dwLocal, ITXDBVERSION);
            }
            UpdateVVLEKL(dwLocal);
        }
        public void InsertVVLEKL(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO VVLEKL(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryVVLEKL(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM VVLEKL WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM VVLEKL  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "VVLEKL";
            Return = Result;
            return Return;
        }
        public void DeleteVVLEKL(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM VVLEKL   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateVVLEKL(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE VVLEKL SET "
                    +"VVLMANDANT= :VVLMANDANT,"
                    +"VVLLEKLNR= :VVLLEKLNR,"
                    +"VVLAENZL= :VVLAENZL,"
                    +"VVLAENB= :VVLAENB,"
                    +"VVLAEND= :VVLAEND,"
                    +"VVLNEUB= :VVLNEUB,"
                    +"VVLNEUD= :VVLNEUD,"
                    +"VVLKUNDNR= :VVLKUNDNR,"
                    +"VVLVB= :VVLVB,"
                    +"VVLKUNDNRL= :VVLKUNDNRL,"
                    +"VVLADRSLL= :VVLADRSLL,"
                    +"VVLVART= :VVLVART,"
                    +"VVLVARTOG= :VVLVARTOG,"
                    +"VVLBHS= :VVLBHS,"
                    +"VVLFRACHT= :VVLFRACHT,"
                    +"VVLPREIS= :VVLPREIS,"
                    +"VVLPREH= :VVLPREH,"
                    +"VVLPREHGRP= :VVLPREHGRP,"
                    +"VVLPREHFKT= :VVLPREHFKT,"
                    +"VVLPWAEHRSL= :VVLPWAEHRSL,"
                    +"VVLVONDAT= :VVLVONDAT,"
                    +"VVLBISDAT= :VVLBISDAT,"
                    +"VVLRECHNR= :VVLRECHNR,"
                    +"VVLWIDERR= :VVLWIDERR,"
                    +"VVLERLKZ= :VVLERLKZ,"
                    +"VVLURLAND= :VVLURLAND,"
                    +"VVLPRFBEG= :VVLPRFBEG,"
                    +"VVLFORM= :VVLFORM,"
                    +"VVLZSACHB= :VVLZSACHB,"
                    +"VVLZOLLTNR= :VVLZOLLTNR,"
                    +"VVLZOLLTRW= :VVLZOLLTRW,"
                    +"VVLDRDAT= :VVLDRDAT,"
                    +"VVLFILLER= :VVLFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("VVLMANDANT", OracleType.NVarChar).Value = dwData["VVLMANDANT"].ToString(); 
          or1.Parameters.Add("VVLLEKLNR", OracleType.NVarChar).Value = dwData["VVLLEKLNR"].ToString(); 
          or1.Parameters.Add("VVLAENZL", OracleType.NVarChar).Value = dwData["VVLAENZL"].ToString(); 
          or1.Parameters.Add("VVLAENB", OracleType.NVarChar).Value = dwData["VVLAENB"].ToString(); 
          or1.Parameters.Add("VVLAEND", OracleType.NVarChar).Value = dwData["VVLAEND"].ToString(); 
          or1.Parameters.Add("VVLNEUB", OracleType.NVarChar).Value = dwData["VVLNEUB"].ToString(); 
          or1.Parameters.Add("VVLNEUD", OracleType.NVarChar).Value = dwData["VVLNEUD"].ToString(); 
          or1.Parameters.Add("VVLKUNDNR", OracleType.NVarChar).Value = dwData["VVLKUNDNR"].ToString(); 
          or1.Parameters.Add("VVLVB", OracleType.NVarChar).Value = dwData["VVLVB"].ToString(); 
          or1.Parameters.Add("VVLKUNDNRL", OracleType.NVarChar).Value = dwData["VVLKUNDNRL"].ToString(); 
          or1.Parameters.Add("VVLADRSLL", OracleType.NVarChar).Value = dwData["VVLADRSLL"].ToString(); 
          or1.Parameters.Add("VVLVART", OracleType.NVarChar).Value = dwData["VVLVART"].ToString(); 
          or1.Parameters.Add("VVLVARTOG", OracleType.NVarChar).Value = dwData["VVLVARTOG"].ToString(); 
          or1.Parameters.Add("VVLBHS", OracleType.NVarChar).Value = dwData["VVLBHS"].ToString(); 
          or1.Parameters.Add("VVLFRACHT", OracleType.NVarChar).Value = dwData["VVLFRACHT"].ToString(); 
          or1.Parameters.Add("VVLPREIS", OracleType.NVarChar).Value = dwData["VVLPREIS"].ToString(); 
          or1.Parameters.Add("VVLPREH", OracleType.NVarChar).Value = dwData["VVLPREH"].ToString(); 
          or1.Parameters.Add("VVLPREHGRP", OracleType.NVarChar).Value = dwData["VVLPREHGRP"].ToString(); 
          or1.Parameters.Add("VVLPREHFKT", OracleType.NVarChar).Value = dwData["VVLPREHFKT"].ToString(); 
          or1.Parameters.Add("VVLPWAEHRSL", OracleType.NVarChar).Value = dwData["VVLPWAEHRSL"].ToString(); 
          or1.Parameters.Add("VVLVONDAT", OracleType.NVarChar).Value = dwData["VVLVONDAT"].ToString(); 
          or1.Parameters.Add("VVLBISDAT", OracleType.NVarChar).Value = dwData["VVLBISDAT"].ToString(); 
          or1.Parameters.Add("VVLRECHNR", OracleType.NVarChar).Value = dwData["VVLRECHNR"].ToString(); 
          or1.Parameters.Add("VVLWIDERR", OracleType.NVarChar).Value = dwData["VVLWIDERR"].ToString(); 
          or1.Parameters.Add("VVLERLKZ", OracleType.NVarChar).Value = dwData["VVLERLKZ"].ToString(); 
          or1.Parameters.Add("VVLURLAND", OracleType.NVarChar).Value = dwData["VVLURLAND"].ToString(); 
          or1.Parameters.Add("VVLPRFBEG", OracleType.NVarChar).Value = dwData["VVLPRFBEG"].ToString(); 
          or1.Parameters.Add("VVLFORM", OracleType.NVarChar).Value = dwData["VVLFORM"].ToString(); 
          or1.Parameters.Add("VVLZSACHB", OracleType.NVarChar).Value = dwData["VVLZSACHB"].ToString(); 
          or1.Parameters.Add("VVLZOLLTNR", OracleType.NVarChar).Value = dwData["VVLZOLLTNR"].ToString(); 
          or1.Parameters.Add("VVLZOLLTRW", OracleType.NVarChar).Value = dwData["VVLZOLLTRW"].ToString(); 
          or1.Parameters.Add("VVLDRDAT", OracleType.NVarChar).Value = dwData["VVLDRDAT"].ToString(); 
          or1.Parameters.Add("VVLFILLER", OracleType.NVarChar).Value = dwData["VVLFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
